package com.luyou.awt.event;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 简单的时间监听
 */
public class EventQs {

    private final Frame frame = new Frame("测试事件");
    Button ok = new Button("确定");
    TextField tf = new TextField();

    public void init(){
        //注册事件监听
        ok.addActionListener(new OkListener());
        frame.add(tf, BorderLayout.NORTH);
        frame.add(ok);
        frame.pack();
        frame.setVisible(true);
    }

    //定义事件处理器,用于响应特定事件
    class OkListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("用户单击了ok按钮");
            tf.setText("Hello world");
        }
    }

    public static void main(String[] args) {
        new EventQs().init();
    }
}
